package com.ljh.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author ：刘剑鸿
 * @date ：Created in 2021/9/9 11:12
 * @description：登录拦截
 * @modified By：
 * @version: $
 */
@Configuration
public class LogintoConfig implements WebMvcConfigurer {

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("login");
        registry.addViewController("/login.html").setViewName("login");
        registry.addViewController("/index.html").setViewName("index");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginHandlerInterceptor())
                .addPathPatterns("/**")                 //拦截所有请求
                .excludePathPatterns("/login.html","/","/user/doLogin","/css/*","/js/**","/img/**","/bootstrap/**","/layer/**","/jquery-validation/**");     //某些请求不拦截
    }
}
